package com.scenery.server.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

import com.scenery.server.services.DianPingServices;
import com.scenery.server.vo.DianPing;

public class DianPingServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		// TODO Auto-generated method stub
		//super.doGet(req, resp);
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("dianping====>");
		resp.setCharacterEncoding("UTF-8");
		DianPingServices dianping=new DianPingServices();
		PrintWriter out=resp.getWriter();
		String action="",userId="",sceneryId="", text="";
		
		action=req.getParameter("action");
		sceneryId=req.getParameter("sceneryId");
		userId=req.getParameter("userId");
		text=req.getParameter("text");
		
		if(action.equals("select"))
		{
			
			List<DianPing> list=dianping.select(sceneryId);
			JSONArray ja=new JSONArray();
			ja.put(list);			
			out.println(ja.toString());
			out.close();
		}else if(action.equals("add"))
		{
			int ret =dianping.addDianPing(userId, sceneryId, text);
			out.println(ret);
			out.close();
		}
	}

}
